{% extends "base.html" %}

{% load static %}

{% block content %}
    <div class="cart_list">
        <div class="cart_top">
            我的订单
            <span style="float: right;">
                <button class="btn">
                    <!-- 需完善a标签href属性 -->
                    <a href="/Buyer/my_order/" style="color: white;">所有订单</a>
                </button>
                <button class="btn">
                    <!-- 需完善a标签href属性 -->
                    <a href="/Buyer/my_order/?but=1" style="color: white;">待支付</a>
                </button>
                <button class="btn">
                    <!-- 需完善a标签href属性 -->
                    <a href="/Buyer/my_order/?but=2" style="color: white;">已支付</a>
                </button>
            </span>
        </div>
        <div class="cart_listbox">
            <div>
                <table>
                    <tr>
                        <th width='20%'>商品名称</th>
                        <th width='10%'>商品缩略图</th>
                        <th width='10%'>商品单价</th>
                        <th width='10%'>支付状态</th>
                        <th width='15%'>总价</th>
                        <th width='15%'>订单号</th>
                        <th width='20%'>操作</th>
                    </tr>
                </table>
            </div>
            {% for order_obj in order_list %}
            <div style="width: 100%;  margin-top: 25px; background: #fbfbf6; ">
                <table width="100%" cellpadding="0" cellspacing="0" border='1px' style="border-collapse:collapse;">
                        {% if order_obj.ordergoods_set.all.count == 1 %}
                            <tr>
                                <th width="20%" >{{ order_obj.ordergoods_set.first.goods_name }}</th>
                                <th width="10%"><img src="/static/{{ order_obj.ordergoods_set.first.goods_picture }}"></th>
                                <th width="10%">{{ order_obj.ordergoods_set.first.goods_price }}</th>

                                {% if order_obj.order_status == "1" %}
                                    <th width="10%" rowspan="{{ order_obj.ordergoods_set.all.count }}">未支付</th>
                                {% elif order_obj.order_status == "2" %}
                                    <th width="10%" rowspan="{{ order_obj.ordergoods_set.all.count }}">已支付</th>
                                {% endif %}

                                <th width="15%" rowspan="{{ order_obj.ordergoods_set.all.count }}">{{ order_obj.order_total }}</th>
                                <th width="15%" rowspan="{{ order_obj.ordergoods_set.all.count }}">{{ order_obj.order_num }}</th>

                                {% if order_obj.order_status == "1" %}
                                    <th width="20%" rowspan="{{ order_obj.ordergoods_set.all.count }}">
                                        <a href="/Buyer/delete_order/?order_id={{ order_obj.id }}">取消订单</a>
                                        <a href="/Buyer/alipay_method/?order_num={{ order_obj.order_num }}&order_id={{ order_obj.id }}&total={{ order_obj.order_total }}">立即付款</a>
                                    </th>
                                {% elif order_obj.order_status == "2" %}
                                    <th width="20%" rowspan="{{ order_obj.ordergoods_set.all.count }}">
                                        <a href="/Buyer/additional_comments/?goods_id={{ order_obj.ordergoods_set.first.goods_id }}">追加评论</a>
                                        <a href="/Buyer/goods_details/?id={{ order_obj.ordergoods_set.first.goods_id }}">商品详情</a>
                                    </th>
                                {% endif %}
                            </tr>
                        {% else %}
                            {% for ordergoods_obj in order_obj.ordergoods_set.all %}
                                {% if ordergoods_obj.id == order_obj.ordergoods_set.all.first.id %}
                                    <tr>
                                        <th width="20%" >{{ ordergoods_obj.goods_name }}</th>
                                        <th width="10%"><img src="/static/{{ ordergoods_obj.goods_picture }}"></th>
                                        <th width="10%">{{ ordergoods_obj.goods_price }}</th>
                                        {% if order_obj.order_status == "1" %}
                                            <th width="10%" rowspan="{{ order_obj.ordergoods_set.all.count }}">未支付</th>
                                        {% elif order_obj.order_status == "2" %}
                                            <th width="10%" rowspan="{{ order_obj.ordergoods_set.all.count }}">已支付</th>
                                        {% endif %}

                                        <th width="15%" rowspan="{{ order_obj.ordergoods_set.all.count }}">{{ order_obj.order_total }}</th>
                                        <th width="15%" rowspan="{{ order_obj.ordergoods_set.all.count }}">{{ order_obj.order_num }}</th>

                                        {% if order_obj.order_status == "1" %}
                                            <th width="20%" rowspan="{{ order_obj.ordergoods_set.all.count }}">
                                                <a href="/Buyer/delete_order/?order_id={{ order_obj.id }}">取消订单</a>
                                                <a href="/Buyer/alipay_method/?order_num={{ order_obj.order_num }}&order_id={{ order_obj.id }}&total={{ order_obj.order_total }}">立即付款</a>
                                            </th>
                                        {% elif order_obj.order_status == "2" %}
                                            <th width="20%">
                                                <a href="/Buyer/additional_comments/?goods_id={{ ordergoods_obj.goods_id }}">追加评论</a>
                                                <a href="/Buyer/goods_details/?id={{ ordergoods_obj.goods_id }}">商品详情</a>
                                            </th>
                                        {% endif %}
                                    </tr>
                                {% else %}
                                    {% if order_obj.order_status == "1" %}
                                        <tr>
                                            <th width="20%" >{{ ordergoods_obj.goods_name }}</th>
                                            <th width="10%"><img src="/static/{{ ordergoods_obj.goods_picture }}"></th>
                                            <th width="10%">{{ ordergoods_obj.goods_price }}</th>
                                        </tr>
                                    {% elif order_obj.order_status == "2" %}
                                        <tr>
                                            <th width="20%" >{{ ordergoods_obj.goods_name }}</th>
                                            <th width="10%"><img src="/static/{{ ordergoods_obj.goods_picture }}"></th>
                                            <th width="10%">{{ ordergoods_obj.goods_price }}</th>
                                            <th width="20%">
                                                <a href="/Buyer/additional_comments/?goods_id={{ ordergoods_obj.goods_id }}">追加评论</a>
                                                <a href="/Buyer/goods_details/?id={{ ordergoods_obj.goods_id }}">商品详情</a>
                                            </th>
                                        </tr>
                                    {% endif %}
                                {% endif %}
                            {% endfor %}
                        {% endif %}
                </table>
            </div>
                {% endfor %}
        </div>
    </div>
{% endblock %}
